<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="content">
            <h:form>
                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <h:outputText escape="false" value="#{bundle.ListPickingOrderEntityEmpty}" rendered="#{pickingOrderEntityController.items.rowCount == 0}"/>
                <p:panel id="dataTablePanel" header="List of picking orders" rendered="#{pickingOrderEntityController.items.rowCount > 0}">
                    <p:dataTable value="#{pickingOrderEntityController.items}" var="item">
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Sales Order #"/>
                            </f:facet>
                            <h:outputText value="#{item.pickList.salesOrder.id}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Reservation #"/>
                            </f:facet>
                            <h:outputText value="#{item.reservation}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Product"/>
                            </f:facet>
                            <h:outputText value="#{item.product.productName}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListPickingOrderEntityTitle_status}"/>
                            </f:facet>
                            <h:outputText value="#{item.status}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Pick Date"/>
                            </f:facet>
                            <h:outputText value="#{item.pickDate}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </p:column>


                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:commandButton id="generateLocationsButton"
                                             disabled="#{item.locationToQuantitySize gt 0}"
                                             update="pickingLocationsTableId, generateLocationsButton, viewLocationsButton, viewLocationsPanel"
                                             action="#{pickingOrderEntityController.generatePickingLocations}" 
                                             value="Generate Pick Locations" 
                                             oncomplete="pickingLocationsDialog.show()">
                                <f:setPropertyActionListener value="#{item}" target="#{pickingOrderEntityController.current}"/>
                            </p:commandButton>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:commandButton id="viewLocationsButton"
                                             disabled="#{item.locationToQuantitySize == 0}"
                                             update="viewLocationsTableId, viewLocationsButton, viewLocationsPanel"
                                             value="View Pick Locations" 
                                             oncomplete="viewLocationsDialog.show()">
                                <f:setPropertyActionListener value="#{item}" target="#{pickingOrderEntityController.current}"/>
                                <f:setPropertyActionListener value="#{item}" target="#{completedGoodsEntityController.pickingOrderEntity}"/>
                                <f:setPropertyActionListener value="#{item.reservation.salesOrder}" target="#{salesOrderEntityController.current}"/>
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>
                   
                </p:panel>
            </h:form>

            <p:dialog id="pickingLocationsDialogId" header="List of locations to pick from" widgetVar="pickingLocationsDialog" width="600" height="250" modal="true">  
                <h:form prependId="false">
                    <p:dataTable id="pickingLocationsTableId" var="pickingLocations" value="#{pickingOrderEntityController.selected.locationToQuantity}" >
                        <p:column headerText="Location">
                            <h:outputLabel for="location" value="#{pickingLocations.location.areaCode}" />
                        </p:column>
                        <p:column headerText="Product">
                            <h:outputLabel for="product" value="#{pickingLocations.inventory.batch.product.productName}" />
                        </p:column>
                        <p:column headerText="Quantity">
                            <h:outputLabel for="locationQuantity" value="#{pickingLocations.quantity}" />
                        </p:column>
                        <p:column headerText="Reservation #">
                            <h:outputLabel for="reservationNumber" value="#{pickingOrderEntityController.selected.id}" />
                        </p:column>
                    </p:dataTable>
                </h:form>
            </p:dialog> 

            <p:dialog id="viewLocationsDialogId" widgetVar="viewLocationsDialog" width="700" height="400" modal="true">  
               
                <h:form prependId="false">
                       
                    <p:panel id="viewLocationsPanel" header="List of locations to pick">
                        <h:outputLabel id="reservationQuantity" value="Amount left to pick: #{completedGoodsEntityController.leftToPick}"/>
                 
                        <p:dataTable id="viewLocationsTableId" var="pickingLocations" value="#{pickingOrderEntityController.selected.locationToQuantity}" >
                            <p:column headerText="Location">
                                <h:outputLabel for="location" value="#{pickingLocations.location.areaCode}" />
                            </p:column>
                            <p:column headerText="Product">
                                <h:outputLabel for="product" value="#{pickingLocations.inventory.batch.product.productName}" />
                            </p:column>
                            <p:column headerText="Quantity">
                                <h:outputLabel for="locationQuantity" value="#{pickingLocations.quantity}" />
                                 
                               
                            </p:column>
                            <p:column headerText="Reservation #">
                                <h:outputLabel for="reservationNumber" value="#{pickingOrderEntityController.selected.reservation.id}" />
                            </p:column>
                            <p:column>
                                
                                <h:inputText   id="minmax" 
                                              value="#{locationQuantityEntityController.toRemoveCase}">
                             
                                    <f:validateLongRange   maximum="#{completedGoodsEntityController.leftToPick}"/>
                                    
                                </h:inputText>
                                <h:message styleClass="errorMsg" for= "minmax"/>
                             

                                <p:commandButton process="@this,minmax,locationPickedButton"
                                               id="locationPickedButton"
                                                 update="viewLocationsTableId,viewLocationsPanel,dataTablePanel"
                                                 value="Picked" 
                                                 action="#{reservationEntityController.fulfilPickingOrder}">
                                    <f:setPropertyActionListener value="#{pickingLocations}" target="#{locationQuantityEntityController.current}"/>
                                </p:commandButton>

                            </p:column>
                        </p:dataTable>
                    </p:panel>
                </h:form>
            </p:dialog> 
    

        </ui:define>
    </ui:composition>

</html>
